# Copyright 2024 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""llava adapter"""

import mindspore as ms
import numpy as np
from mindspore import dtype as mstype
from mindspore import nn, Parameter, Tensor
from mindspore import ops
from mindspore.ops import operations as P

from mindformers.modules.layers import LayerNorm
from mindformers.models.clip.clip_modules import Transformer
from mindformers.modules.layers import Linear
from llava_config import LlavaConfig


class LlavaAdapter(nn.Cell):
    def __init__(self, config: LlavaConfig):
        super(LlavaAdapter, self).__init__(config)

        self.adapter = Linear(
            in_channels=config.vision_config.hidden_size,
            out_channels=config.text_config.hidden_size,
            compute_dtype=config.compute_dtype
        )

    def construct(self, x):
        output = self.adapter(x)
        return output
